package com.yun.zf.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yun.zf.common.admin.domain.SysPost;
import com.yun.zf.common.admin.dto.sys.PostListDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 岗位信息 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface SysPostMapper extends BaseMapper<SysPost> {

    /**
     * 查询所有岗位
     *
     * @return 岗位列表
     */
    public List<SysPost> selectPostAll();

    /**
     * 根据用户ID获取岗位选择框列表
     *
     * @param userId 用户ID
     * @return 选中岗位ID列表
     */
    public List<Integer> selectPostListByUserId(Long userId);



    /**
     * 删除岗位信息
     *
     * @param postId 岗位ID
     * @return 结果
     */
    public int deletePostById(Long postId);

    /**
     * 批量删除岗位信息
     *
     * @param postIds 需要删除的岗位ID
     * @return 结果
     */

    @Delete("<script>" +
            "delete from sys_post where post_id in\n" +
            " <foreach collection=\"array\" item=\"postId\" open=\"(\" separator=\",\" close=\")\">\n" +
            " #{postId}\n" +
            " </foreach> " +
            "</script>")
    public int deletePostByIds(Long[] postIds);


    @Update("<script>" +
            "update sys_post\n" +
            " <set>\n" +
            " <if test=\"postCode != null and postCode != ''\">post_code = #{postCode},</if>\n" +
            "  <if test=\"postName != null and postName != ''\">post_name = #{postName},</if>\n" +
            "  <if test=\"postSort != null and postSort != ''\">post_sort = #{postSort},</if>\n" +
            "  <if test=\"status != null and status != ''\">status = #{status},</if>\n" +
            "  <if test=\"remark != null\">remark = #{remark},</if>\n" +
            "  <if test=\"updateBy != null and updateBy != ''\">update_by = #{updateBy},</if>\n" +
            "  update_time = sysdate()\n" +
            " </set>\n" +
            " where post_id = #{postId}" +
            "</script>")
    public int updatePost(SysPost post);

    @Select("<script>" +
            " SELECT post_id,post_code,post_name from sys_post WHERE `status`=0 " +
            "</script>")
    List<PostListDto> getInAgentPost();

}
